package com.cwj.mansysback.dao.impl;

import com.cwj.mansysback.dao.BaseDao;
import com.cwj.mansysback.dao.api.LocalAccountDao;
import com.cwj.mansysback.entity.LocalAccount;

import java.sql.Timestamp;

public class LocalAccountDaoImpl extends BaseDao<LocalAccount> implements LocalAccountDao {

    String tableName="localAccount";

    @Override
    public boolean addLocalAccount(LocalAccount loAcc) {

        String sql = "insert into" + tableName + "(aid,accrank,lastTime,idCard) values (?,?,?,?)";

        return super.update(sql,loAcc.getAid(),loAcc.getAccrank(),loAcc.getLoginTime(),loAcc.getIdCard()) > 0;
    }

    @Override
    public LocalAccount selectAccount(String idCard) {

        String sql = "select aid,accrank,idCard,lastTime AS loginTime from\t" + this.tableName + "\twhere idCard = ?";

        return super.select(LocalAccount.class,sql,idCard);
    }

    @Override
    public boolean deleteAccount(String idCard) {

        String sql = " delete from  " + this.tableName + " where idCard = ?";

        return super.update(sql,idCard) > 0;
    }

    @Override
    public boolean clearAccount(Timestamp tp) {

        String sql = "delete from " + this.tableName + "\t where lastTime < ?";

        return super.update(sql,tp) > 0;
    }
}
